<template>
  <div>
    <span></span>
    <el-button style="margin-left: 20px; margin-top: 20px;" type="primary" @click="openDialogReg">修改注册页面标题</el-button>
    <el-button style="margin-left: 20px; margin-top: 20px;" type="primary" @click="openDialog">修改登入页面标题</el-button>
    <el-button style="margin-left: 20px; margin-top: 20px;" type="primary" @click="openLogDiaUser">修改用户登入后的页面标题</el-button>
    <el-dialog :visible.sync="openDiaUser"  title="登入页面的标题的修改">
      <el-table
            :data="tableData"
            max-height="400px"
            style="width: 100%">
            <el-table-column
              prop="userName"
              label="用户名"
              width="180">
            </el-table-column>
            <el-table-column
              prop="createBy"
              label="创建人"
              width="180">
            </el-table-column>
            <el-table-column
              prop="title"
              label="标题"
              width="300px">
            </el-table-column>
                <el-table-column  label="操作" width="100">
                  <template slot-scope="scope">
                    <el-button type="text" size="small"  @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                  </template>
                </el-table-column>
          </el-table>
<!--      <el-row :gutter="15">
        <el-form ref="formDataLogUser" :model="formDataLogUser" :rules="rules2" size="medium" label-width="100px">
          <el-col :span="14">
            <el-form-item label="登入页面的标题" prop="loginTitle" label-width="120px">
              <el-input v-model="formDataLogUser.title" placeholder="登入页面的标题" :style="{width: '50%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="14">
             <el-button style="margin-left: 20px;" type="primary" @click="submitFormUser">提交</el-button>
          </el-col>
        </el-form>
      </el-row> -->
    </el-dialog>
    <el-dialog :visible.sync="openUser" title="用户信息的修改">
      <el-row :gutter="15">
        <el-form ref="user" :model="user" :rules="rules4" size="medium" label-width="100px">
          <el-col :span="14">
            <el-form-item label="用户名" prop="" label-width="120px">
              <el-input v-model="user.userName" placeholder="用户名" :style="{width: '50%'}" readonly></el-input>
            </el-form-item>
            <el-form-item label="标题" prop="" label-width="120px">
              <el-input v-model="user.title" placeholder="标题" :style="{width: '50%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="14">
             <el-button style="margin-left: 20px;" type="primary" @click="submitFormUser">提交</el-button>
          </el-col>
        </el-form>
      </el-row>
    </el-dialog>
    <el-dialog :visible.sync="openLogDia" title="登入页面的标题的修改">
      <el-row :gutter="15">
        <el-form ref="formDataLog" :model="formDataLog" :rules="rules1" size="medium" label-width="100px">
          <el-col :span="14">
            <el-form-item label="登入页面的标题" prop="loginTitle" label-width="120px">
              <el-input v-model="formDataLog.loginTitle" placeholder="登入页面的标题" :style="{width: '50%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="14">
             <el-button style="margin-left: 20px;" type="primary" @click="submitFormLog">提交</el-button>
          </el-col>
        </el-form>
      </el-row>
    </el-dialog>
    <!-- 添加对话框 -->
    <el-dialog :visible.sync="dialogVisible" title="注册页面的标题修改">
      <el-row :gutter="15">
        <el-form ref="formDataReg" :model="formDataReg" :rules="rules" size="medium" label-width="100px">
          <el-col :span="14">
            <el-form-item label="注册页面的标题" prop="registerTitle" label-width="120px">
              <el-input v-model="formDataReg.registerTitle" placeholder="注册页面的标题" :style="{width: '50%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="14">
            <el-form-item label="平台签名" prop="signature" label-width="120px">
               <el-input v-model="formDataReg.signature" placeholder="平台签名" :style="{width: '50%'}"></el-input>
            </el-form-item>
          </el-col>
<!--          <el-col :span="14">
            <el-form-item label="医院ID" prop="hospitalId" label-width="120px">
              <el-input v-model="formDataReg.hospitalId" placeholder="医院ID" :style="{width: '50%'}"></el-input>
            </el-form-item>
          </el-col> -->
          <el-col :span="14">
             <el-button style="margin-left: 20px;" type="primary" @click="submitFormReg">提交</el-button>
          </el-col>
        </el-form>
      </el-row>
    </el-dialog>
  </div>
</template>
<script>
import { updateLog,updateReg } from "@/api/his/title";
import { getUserInfo,updateUser } from "@/api/system/user";

export default {
  name: 'title',
  data() {
    return {
      formDataReg: {
        registerTitle: '',
        signature: '',
        hospitalId: ''
      },
      tableData: [],
      formDataLogUser: {
        registerTitle: '',
        userId: null,
        signature: '',
        hospitalId: ''
      },
      formDataLog: {
        loginTitle: ''
      },
      user: {
        userName: '',
        title: '',
        userId: '',
      },
      rules1: {
        loginTitle: [
          { required: true, message: '标题不能为空', trigger: 'blur' }
        ]
      },
      rules2: {
        // loginTitle: [
        //   { required: true, message: '标题不能为空', trigger: 'blur' }
        // ]
      },
      // 添加表单验证规则
      rules: {
        registerTitle: [
          { required: true, message: '注册页面的标题不能为空', trigger: 'blur' }
        ],
        signature: [
          { required: true, message: '平台签名不能为空', trigger: 'blur' }
        ],
        // hospitalId: [
        //   { required: true, message: '医院ID不能为空', trigger: 'blur' }
        // ]
      },
      rules4: {
        title: [
          { required: true, message: '标题不能为空', trigger: 'blur' }
        ],
        // hospitalId: [
        //   { required: true, message: '医院ID不能为空', trigger: 'blur' }
        // ]
      },
      dialogVisible: false, // 控制对话框显示与隐藏的变量
      openLogDia: false, // 控制对话框显示与隐藏的变量
      openDiaUser: false, //
      openUser: false, //
    }
  },
  mounted() {

  },
  methods: {
     handleEdit(index, row) {
       // alert(JSON.stringify(row))
       this.openUser = true;
       this.user=row;
       // console.log(index, row);
          },
    openLogDiaUser() {
      this.getUser();
      // 点击按钮打开对话框
      this.openDiaUser = true;
    },
    getUser(){
      getUserInfo().then(response =>{
        this.tableData = response;
        // alert(JSON.stringify(response))
      });
    },
    openDialogReg() {
      // 点击按钮打开对话框
      this.dialogVisible = true;
    },
    openDialog() {
      // 点击按钮打开对话框
      this.openLogDia = true;
    },
    submitFormUser() {
      this.$refs.user.validate((valid) => {
        if (valid) {
          // 表单验证通过，执行提交操作
          updateUser(this.user).then(response => {
            this.$message.success('修改成功！');
            this.openUser = false;
          }).catch(error => {
            this.$message.error('系统繁忙，请稍后重试！');
             this.openUser = false;
          });
        } else {
          this.$message.error('表单验证失败，请检查输入！');
        }
      });
    },
    submitFormReg() {
      this.$refs.formDataReg.validate((valid) => {
        if (valid) {
          // 表单验证通过，执行提交操作
          updateReg(this.formDataReg).then(response => {
            this.$message.success('修改成功！');
            this.dialogVisible = false;
          }).catch(error => {
            this.$message.error('系统繁忙，请稍后重试！');
             this.dialogVisible = false;
          });
        } else {
          this.$message.error('表单验证失败，请检查输入！');
        }
      });
    },
    submitFormLog() {
      this.$refs.formDataLog.validate((valid) => {
        if (valid) {
          // 表单验证通过，执行提交操作
          updateLog(this.formDataLog).then(response => {
            this.$message.success('修改成功！');
            this.openLogDia = false;
          }).catch(error => {
            this.$message.error('系统繁忙，请稍后重试！');
             this.openLogDia = false;
          });
        } else {
          this.$message.error('表单验证失败，请检查输入！');
        }
      });
    }
  }
}
</script>
<style scoped lang="scss">

</style>
